<template>
  <div id="app" class="app">
    <router-view />
  </div>
</template>

<script>
import { defineComponent, onMounted, onUnmounted } from 'vue'

export default defineComponent({
  name: 'App',
  setup() {
    // 监听系统主题变化
    const handleThemeChange = () => {
      const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches
      document.documentElement.classList.toggle('dark', isDark)
    }
    
    // 监听网络状态
    const handleNetworkChange = () => {
      const isOnline = navigator.onLine
      if (!isOnline) {
        console.warn('网络连接已断开')
      }
    }
    
    // 生命周期
    onMounted(() => {
      // 监听主题变化
      window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', handleThemeChange)
      
      // 监听网络状态
      window.addEventListener('online', handleNetworkChange)
      window.addEventListener('offline', handleNetworkChange)
      
      // 初始化网络状态
      handleNetworkChange()
    })
    
    onUnmounted(() => {
      window.matchMedia('(prefers-color-scheme: dark)').removeEventListener('change', handleThemeChange)
      window.removeEventListener('online', handleNetworkChange)
      window.removeEventListener('offline', handleNetworkChange)
    })
    
    return {}
  }
})
</script>

<style lang="scss">
.app {
  min-height: 100vh;
  background-color: var(--el-bg-color);
  transition: background-color 0.3s ease;
}

// 全局样式
* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  line-height: 1.5;
  
  // 响应式字体大小
  @media (max-width: 768px) {
    font-size: 14px;
  }
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--el-font-family);
  color: var(--el-text-color-primary);
  background-color: var(--el-bg-color);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

// 滚动条样式
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--el-fill-color-lighter);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--el-fill-color-dark);
  border-radius: 4px;
  
  &:hover {
    background: var(--el-fill-color-darker);
  }
}

// 链接样式
a {
  color: var(--el-color-primary);
  text-decoration: none;
  
  &:hover {
    color: var(--el-color-primary-light-3);
  }
}

// 图片样式
img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

// 表单元素样式
input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

// 按钮样式
button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

// 表格样式
table {
  border-collapse: collapse;
  width: 100%;
}

// 辅助类
.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.d-flex {
  display: flex;
}

.d-block {
  display: block;
}

.d-inline-block {
  display: inline-block;
}

.d-none {
  display: none;
}

.w-100 {
  width: 100%;
}

.h-100 {
  height: 100%;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-1 {
  flex: 1;
}

.mb-0 {
  margin-bottom: 0;
}

.mt-0 {
  margin-top: 0;
}

.p-0 {
  padding: 0;
}

.border-0 {
  border: 0;
}

// 响应式工具类
@media (max-width: 768px) {
  .hidden-mobile {
    display: none !important;
  }
  
  .visible-mobile {
    display: block !important;
  }
}

@media (min-width: 769px) {
  .hidden-desktop {
    display: none !important;
  }
  
  .visible-desktop {
    display: block !important;
  }
}

// 动画类
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: transform 0.3s ease;
}

.slide-enter-from {
  transform: translateX(-100%);
}

.slide-leave-to {
  transform: translateX(100%);
}

// 加载动画
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

// 错误页面样式
.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  
  .error-code {
    font-size: 6rem;
    font-weight: bold;
    color: var(--el-color-primary);
    margin-bottom: 1rem;
  }
  
  .error-message {
    font-size: 1.5rem;
    color: var(--el-text-color-regular);
    margin-bottom: 2rem;
  }
  
  .error-description {
    color: var(--el-text-color-secondary);
    margin-bottom: 2rem;
  }
}

// 打印样式
@media print {
  .no-print {
    display: none !important;
  }
  
  .print-only {
    display: block !important;
  }
}
</style> 